<template>
  <view>
    <!-- 轮播图 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :current="true">
      <swiper-item class="swiper-item" v-for="(item,index) in swiperList" :key="index">
       <image :src="item.image_src" @click="goDetail(item)"></image>
      </swiper-item>
    </swiper>
    <!-- 分类 -->
    <view class="cate-list">
      <view class="cate-item" v-for="(item,index) in cateList" :key="index">
        <image :src="item.image_src" @click="goCate(item)"></image>
      </view>
    </view>
    <!-- 楼层区域 -->
    <view class="floor-list">
      <!-- 整个floor图片一起for循环 -->
     <view class="floor-item" v-for="(item,index) in floorList" :key="index">
       <view class="top">
          <image :src="item.floor_title.image_src"></image>
       </view>
     
      <!-- 下，图片 -->
      <view class="bottom">
        <view class="left">
          <image @click="goList(item.product_list[0])" class="floor-img" :src="item.product_list[0].image_src"
          :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"
          ></image>
        </view>
        <view class="right">
          <image @click="goList(e)" class="floor-img" v-for="(e,i) in item.product_list" :src="e.image_src" :key="i" v-if="i!==0" mode="" 
          :style="{width:e.image_width+'rpx'}"
          mode="widthFix"
          ></image>
        </view>
      </view>
    </view>
  </view>
</view>
</template>

<script>
  export default {
    data() {
      return {
        //轮播图列表
        swiperList: [],
        cateList:[],
        floorList:[]
      }
    },
    onLoad() {
      // 相当于created，调用方法，获取数据
      this.getSwiperList()
      this.getCateList()
      this.getFloorList()
    },
    methods: {
      // 点击floor图片，跳转
      goList(item){
        const query = item.navigator_url.split('?')[1]
        uni.navigateTo({
          url:`/subpkg/goods_list/goods_list?${query}`
        })
      },
      // 点击分类去往分类tabbar
      goCate(item){
        if(item.name=='分类'){
        uni.switchTab({
          url:'/pages/cate/cate'
        })
        }
      },
      // 点击轮播图去往详情页
      goDetail(item){
        uni.navigateTo({
          url: `/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`
        })
      },
      // 获取轮播图数据
      async getSwiperList() {
        const {
          data:{message,meta}
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        console.log(message)
        if (meta.status !== 200) {
          return uni.$showMsg()
        }
        this.swiperList = message
      },
      // 获取分类选项数据
     async getCateList(){
       const {data:{message,meta}} = await uni.$http.get('/api/public/v1/home/catitems')
       // console.log(message)
       if(meta.status!==200){
         return uni.$showMsg()
       }
       this.cateList=message
      },
      // 获取楼层数据
     async getFloorList(){
       const {data:{message,meta}} = await uni.$http.get('/api/public/v1/home/floordata')
     if(meta.status!==200)
      return uni.$showMsg()
      this.floorList=message
      }
    }
  };
  
</script>

<style lang="scss">
swiper{
.swiper-item{
  image{
    width: 100%;
    height: 330rpx;
  }
 }
}
.cate-list{
  display: flex;
  justify-content: space-around;
  margin: 5px 0;
  .cate-item{
    image{
      width: 128rpx;
      height: 140rpx;
    }
  }
}
.floor-list{
  .floor-item{
    padding: 0 5px;
    .top{
      image{
     // display: flex;
     height: 60rpx;
     width: 100%;
   }
  }
  .bottom{
    display: flex;
    .floor-img{
      display: block;
      }
    .left{
      margin-right: 5px;
    }
    .right{
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
    }
  }
  }
}
</style>
